package cn.jobstart.spider.pageProcessor;

import cn.jobstart.enums.HtmlTypeFleEnum;
import cn.jobstart.enums.TalentSubscriptionTaskChannelEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import us.codecraft.webmagic.Site;

/**
 * @author sunke
 * @version 1.0
 * @Description
 * @date 2023-10-18 15:45
 */

@Data
@Slf4j
public abstract class HtmlPageProcessor extends AbstractPageProcessor {




    public static HtmlPageProcessor getProcessor(int source, int typeFlag) {

        if (source == TalentSubscriptionTaskChannelEnum.JOB51.getType().intValue() && typeFlag == HtmlTypeFleEnum.Talent.getType()) {

            HtmlPageProcessor pageProcessor = new TalentJob51HtmlPageProcessor();

            return pageProcessor;


        }


        return null;


    }

    /**
     * 0：人才 1：企业
     *
     * @return
     */
    public abstract int getTypeFlag();

    public String getChildText(Elements elements, int i, int j) {
        try {
            return getChildText(elements.get(i), j);
        } catch (Exception e) {

        }
        return "";

    }

    public String getFirstElementText(Elements elements) {

        return getIndexElementText(elements, 0);

    }

    public String getIndexElementText(Elements elements, int index) {
        try {
            return elements.get(index).text();
        } catch (Exception e) {

        }
        return "";

    }


    public String getChildText(Element element, int index) {
        try {
            if (element == null) {
                return "";
            }
            return element.child(index).text();

        } catch (Exception e) {

        }
        return "";
    }


    /**
     * get the site settings
     *
     * @return site
     * @see Site
     */
    @Override
    public Site getSite() {

        return Site.me();
    }
}
